package com.softeem.music.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.softeem.music.comm.R;
import com.softeem.music.entity.Album;
import com.softeem.music.service.AlbumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * 专辑控制层:专辑列表、专辑详情、专辑添加、专辑修改、专辑删除
 */
@Tag(name = "专辑管理")
@RestController
public class AlbumController {
    @Autowired
    private AlbumService albumService;
    @Operation(summary = "专辑列表",description = "根据提供的页码和数据条数实现分页查询")
    @Parameters({
            @Parameter(name = "page",description = "页码",required = true),
            @Parameter(name = "limit",description = "数据条数",required = true)
    })
    @GetMapping("/album/list")
    public R list(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "6") Integer limit){
        //创建分页对象
        IPage<Album> iPage = new Page<Album>(page,limit);
        //执行查询(分页) select * from album limit ?,?
        List<Album> list = albumService.list(new Page<Album>(page,limit));
        //返回结果
        return R.success().setData(list);
    }

    @Operation(summary = "所有专辑",description = "查询所有专辑列表")
    @GetMapping("/album/listAll")
    public R list(){
        return R.success().setData(albumService.list());
    }

}
